#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <complex>

using namespace cv;
using namespace std;

typedef complex<float> usetype;

void cvabs( Mat * M, Mat * Mabs )
{
	const int Mrows = M->rows;
	const int Mcols = M->cols;
	*Mabs = Mat(Mrows, Mcols, CV_32FC1); // update to CV_64FC1 if you change the usetype typedef to use double precision.

	for(int i = 0; i < Mrows; i++)
	{
		for(int j = 0; j < Mcols; j++)
		{
			Mabs->at<float>(i,j) = abs(M->at<usetype>(i,j)); // update the <float> to <double> if you change the usetype typedef. Sorry!
		}
	}
}